import { useAppStore } from "@/stores";
import { storeToRefs } from "pinia";
import {ref,onMounted,onBeforeUnmount} from 'vue'
/**
 * 递归调用接口
 * @param methods 递归方法名
 * @param paramArr 递归数组
 * @param i 递归索引
 * @returns 
 */
const apiRecursion = async(methods,paramArr,i) => {
	const useApp = useAppStore();
	let { tempArr } = storeToRefs(useApp);
	try {
		let parm = JSON.parse(JSON.stringify(paramArr[i]));
		let res =await methods(parm)
	} catch (error) {
		console.log(error);
	} 
	if (++i < paramArr.length) {
		apiRecursion(methods,paramArr,i); //循环调用
	}  
	if(i=== paramArr.length){
		tempArr.value.push(true)
	}else{
		tempArr.value.push(false)
	}
	console.log(tempArr.value)
}

//动态获取屏幕宽高
const useWinSize=()=>{
	let winWidth,winHeight
    // 获取窗口宽度
	if  (window.innerWidth)
		winWidth = window.innerWidth;
	else if ((document.body) && (document.body.clientWidth))
		winWidth = document.body.clientWidth;
	// 获取窗口高度
	if  (window.innerHeight)
		winHeight = window.innerHeight;
	else if ((document.body) && (document.body.clientHeight))
		winHeight = document.body.clientHeight;
	// 通过深入 Document 内部对 body 进行检测，获取窗口大小
	if  (document.documentElement && document.documentElement.clientHeight && document.documentElement.clientWidth)
	{
		winHeight = document.documentElement.clientHeight;
		winWidth = document.documentElement.clientWidth;
	}
	return {
		width:winWidth,
		height:winHeight
	}
}
export { apiRecursion,useWinSize }
